import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useTokenStore = defineStore('mytoken', () => {


  const token = ref('')

  // const token = computed(() => {
  //   return JSON.parse(tokenJson.value)
  // })

  const saveToken = (data:any) => {
    token.value = data
    //将token保存在本地
    // window.localStorage.setItem("token", data)
    console.log("test"+ data)
    var item = localStorage.getItem("token")
    console.log("有了:"+ item)
  }

  const removeToken = () => {
    token.value = ''
    window.localStorage.removeItem("token")
  }

  return { token,saveToken, removeToken }
},
  {
    persist:true //持久化存储
  }
);
